//
//  HNThreeGoodEvaView.m
//  优学荟管理系统
//
//  Created by edz on 2017/12/6.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "HNThreeGoodEvaView.h"
#import "HNThreeGoodEvaCell.h"

@implementation HNThreeGoodEvaView
{
    __weak IBOutlet UIView *_ContentView;
    __weak IBOutlet NSLayoutConstraint *_ContentViewHeight;
    NSArray <HNCourseListChartsModel *>*_DataArr;
    void (^_CallBack)(CGFloat Heigt);
}

+ (instancetype)ConfigEvaViewWithDataArr:(NSArray <HNCourseListChartsModel *>*)DataArr CallBack:(void (^)(CGFloat Heigt))CallBack {
    
    return [[self alloc] initWithDataArr:DataArr CallBack:CallBack];
}

- (instancetype)initWithDataArr:(NSArray <HNCourseListChartsModel *>*)DataArr CallBack:(void (^)(CGFloat Heigt))CallBack {
    
    self = [[NSBundle mainBundle] loadNibNamed:[HNThreeGoodEvaView description] owner:nil options:nil][0];
    if (self) {
        
        _DataArr = DataArr;
        _CallBack = CallBack;

    }
    return self;
}


- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    [_DataArr enumerateObjectsUsingBlock:^(HNCourseListChartsModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        HNThreeGoodEvaCell *View = [HNThreeGoodEvaCell ConfigEvaCellWithTitle:obj.content andNum:[obj.commentCount integerValue] andTrailing:([obj.totleCommentCount isEqualToNumber:@0] ? 0:[obj.commentCount floatValue] / [obj.totleCommentCount floatValue])];
        [_ContentView addSubview:View];
        [View mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(_ContentView.mas_top).mas_offset(30 * idx);
            make.left.right.equalTo(_ContentView);
            make.height.equalTo(@30);
        }];
    }];
    
    _CallBack ? _CallBack ( 44 + 30 * _DataArr.count) : nil;
}

@end
